package com.atstudy.date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2022/12/21 13:50
 * @copyright: 博为峰
 */
public class DateDemo {
    public static void main(String[] args) throws ParseException {
//        m1();
//        m2();

        //2022-12-21  String->Date
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = format.parse("2022-12-21 15:16:17");
        System.out.println(date);
    }

    private static void m2() {
        Date date = new Date();

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //Date->String
        String str = format.format(date);
        System.out.println(str);
    }

    private static void m1() {
        //当前时间
        Date date = new Date();
        System.out.println(date);

        long time = date.getTime();
        System.out.println(time);//1671602074166

        Date his = new Date(1671602074166L);
        System.out.println(his);
    }
}
